package com.tourism.website.articledisplay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tourism.website.articledisplay.entity.Article;
import com.tourism.website.articledisplay.entity.Category;
import com.tourism.website.articledisplay.mapper.CategoryMapper;
import com.tourism.website.articledisplay.service.ICategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tourismwebsite.articledisplay.dto.ArticleDTO;
import com.tourismwebsite.articledisplay.dto.CategoryDTO;
import com.tourismwebsite.collection.dto.FavoriteDTO;
import org.mapstruct.Mapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lyc
 * @since 2024-06-11
 */
@Mapper(componentModel="spring")
interface MsCategoryMapper{
    CategoryDTO CategoryToCategoryDTO(Category category);
}

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {
   @Resource
   MsCategoryMapper msCategoryMapper;
    @Override
    public List<CategoryDTO> queryAllCategory() {
        LambdaQueryWrapper<Category> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(Category::getCategoryId,Category::getCategoryPid, Category::getCategoryName);
        List<Category> categories = baseMapper.selectList(wrapper);
        List<CategoryDTO> categoryDTOs = categories.stream()
                .map(category -> msCategoryMapper.CategoryToCategoryDTO(category))
                .collect(Collectors.toList());
        return categoryDTOs;
    }
}
